package com.app.juyanresturantapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.juyanresturantapp.R;
import com.app.juyanresturantapp.bean.FoodsBean;
import com.squareup.picasso.Picasso;

import java.util.List;

public class MyAdapter extends BaseAdapter {
    Context context;
    List list;

    public MyAdapter(Context context, List list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.activity_product_listview,parent,false);

        TextView listTitle = view.findViewById(R.id.listTitle);
        ImageView listPic = view.findViewById(R.id.listPic);
        TextView listContent = view.findViewById(R.id.listContent);
        TextView listPrice = view.findViewById(R.id.listPrice);

        FoodsBean.ListDTO listBean = (FoodsBean.ListDTO) list.get(position);
        listTitle.setText(listBean.getName());
        listPrice.setText(String.valueOf(listBean.getPrice()));
        listContent.setText(listBean.getLabel());

        Picasso.with(context).load(view.getResources().getString(R.string.url)+listBean.getIcon()).into(listPic);


        return view;
    }
}
